'''可以以元组形式传递标签消息'''

from p10_defining_an_actor_task import Actor
class TaggedActor(Actor):
    def run(self):
        while True:
             # *payload表示任意数量参数
             tag, *payload = self.recv()
             getattr(self,'do_'+tag)(*payload)

    # Methods correponding to different message tags
    def do_A(self, x):
        print('Running A', x)

    def do_B(self, x, y):
        print('Running B', x, y)

def recipe1():
    a = TaggedActor()
    a.start()
    a.send(('A', 1))      # Invokes do_A(1)
    a.send(('B', 2, 3))   # Invokes do_B(2,3)
    a.close()
    a.join()

def main():
    print('recipe1'.center(20, '*'))
    recipe1()


if __name__ == '__main__':
    main()           